{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 七月在线机器学习集训营六期第二周(Pandas数据处理)考试\n",
    "#### 考试说明:\n",
    "- 起止时间：请同学在2018年11月2日至11月4日期间完成，最晚提交时间本周日（11月4日24时之前）结束，<b>逾期不接受补考,该考试分数计入平时成绩</b>\n",
    "- 考试提交方式：请同学<font color=red><b>拷贝</b></font>该试卷后，将文件更名为同学姓名拼音-exam1（例如wangwei-exam2）后，移动至/0.Teacher/Exam/2/目录下进行作答。\n",
    "- 注意事项：为确保同学们真正了解自身对本周课程的掌握程度，<font color=red><b>请勿翻阅，移动，更改</b></font>其它同学试卷。如发现按0分处理\n",
    "- 请同学在下方同学姓名处填写自己的姓名，批改人和最终得分处不用填写"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "- 同学姓名：段绪勇\n",
    "- 批改人：   \n",
    "- 最终得分:"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<center><h1>####答卷开始####</h1></center>\n",
    "***"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Pandas操作题(共两题。每题每个步骤分数均已标明。总分100分)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 1.学生数据分析（总分数：60）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1.数据导入并展示, 文件位置位于0.Teacher/data/下（10分）\n",
    "   - 请将文件student-info.csv中的内容读入pandas DataFrame \"df_info\"，注意该文件的分隔符是分号，并展示前五行（5分）   \n",
    "   - 请将文件student-score.csv中的内容读入pandas DataFrame \"df_score\"，注意该文件的分隔符是分号，并展示前五行（5分）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>school</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>address</th>\n",
       "      <th>famsize</th>\n",
       "      <th>Pstatus</th>\n",
       "      <th>Medu</th>\n",
       "      <th>Fedu</th>\n",
       "      <th>Mjob</th>\n",
       "      <th>...</th>\n",
       "      <th>higher</th>\n",
       "      <th>internet</th>\n",
       "      <th>romantic</th>\n",
       "      <th>famrel</th>\n",
       "      <th>freetime</th>\n",
       "      <th>goout</th>\n",
       "      <th>Dalc</th>\n",
       "      <th>Walc</th>\n",
       "      <th>health</th>\n",
       "      <th>absences</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>GP</td>\n",
       "      <td>F</td>\n",
       "      <td>18</td>\n",
       "      <td>U</td>\n",
       "      <td>GT3</td>\n",
       "      <td>A</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>at_home</td>\n",
       "      <td>...</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>GP</td>\n",
       "      <td>F</td>\n",
       "      <td>17</td>\n",
       "      <td>U</td>\n",
       "      <td>GT3</td>\n",
       "      <td>T</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>at_home</td>\n",
       "      <td>...</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>GP</td>\n",
       "      <td>F</td>\n",
       "      <td>15</td>\n",
       "      <td>U</td>\n",
       "      <td>LE3</td>\n",
       "      <td>T</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>at_home</td>\n",
       "      <td>...</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>GP</td>\n",
       "      <td>F</td>\n",
       "      <td>15</td>\n",
       "      <td>U</td>\n",
       "      <td>GT3</td>\n",
       "      <td>T</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>health</td>\n",
       "      <td>...</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>yes</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>GP</td>\n",
       "      <td>F</td>\n",
       "      <td>16</td>\n",
       "      <td>U</td>\n",
       "      <td>GT3</td>\n",
       "      <td>T</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>other</td>\n",
       "      <td>...</td>\n",
       "      <td>yes</td>\n",
       "      <td>no</td>\n",
       "      <td>no</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 31 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   ID school sex  age address famsize Pstatus  Medu  Fedu     Mjob   ...     \\\n",
       "0   0     GP   F   18       U     GT3       A     4     4  at_home   ...      \n",
       "1   1     GP   F   17       U     GT3       T     1     1  at_home   ...      \n",
       "2   2     GP   F   15       U     LE3       T     1     1  at_home   ...      \n",
       "3   3     GP   F   15       U     GT3       T     4     2   health   ...      \n",
       "4   4     GP   F   16       U     GT3       T     3     3    other   ...      \n",
       "\n",
       "  higher internet romantic  famrel  freetime  goout Dalc Walc health absences  \n",
       "0    yes       no       no       4         3      4    1    1      3        6  \n",
       "1    yes      yes       no       5         3      3    1    1      3        4  \n",
       "2    yes      yes       no       4         3      2    2    3      3       10  \n",
       "3    yes      yes      yes       3         2      2    1    1      5        2  \n",
       "4    yes       no       no       4         3      2    1    2      5        4  \n",
       "\n",
       "[5 rows x 31 columns]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>G1</th>\n",
       "      <th>G2</th>\n",
       "      <th>G3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>15</td>\n",
       "      <td>14</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>6</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ID  G1  G2  G3\n",
       "0   0   5   6   6\n",
       "1   1   5   5   6\n",
       "2   2   7   8  10\n",
       "3   3  15  14  15\n",
       "4   4   6  10  10"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "si=pd.read_csv('./Data/student-info.csv',sep=';')\n",
    "sc=pd.read_csv('./Data/student-score.csv',sep=';')\n",
    "si.head()\n",
    "sc.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 2.把两个DataFrame \"df_info\" 和 \"df_score\" 按照学生ID对齐拼接起来，结果存在一个新DataFrame \"df\" 中 (5分）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ID</th>\n",
       "      <th>school</th>\n",
       "      <th>sex</th>\n",
       "      <th>age</th>\n",
       "      <th>address</th>\n",
       "      <th>famsize</th>\n",
       "      <th>Pstatus</th>\n",
       "      <th>Medu</th>\n",
       "      <th>Fedu</th>\n",
       "      <th>Mjob</th>\n",
       "      <th>...</th>\n",
       "      <th>famrel</th>\n",
       "      <th>freetime</th>\n",
       "      <th>goout</th>\n",
       "      <th>Dalc</th>\n",
       "      <th>Walc</th>\n",
       "      <th>health</th>\n",
       "      <th>absences</th>\n",
       "      <th>G1</th>\n",
       "      <th>G2</th>\n",
       "      <th>G3</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>0</td>\n",
       "      <td>GP</td>\n",
       "      <td>F</td>\n",
       "      <td>18</td>\n",
       "      <td>U</td>\n",
       "      <td>GT3</td>\n",
       "      <td>A</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>at_home</td>\n",
       "      <td>...</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>6</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>GP</td>\n",
       "      <td>F</td>\n",
       "      <td>17</td>\n",
       "      <td>U</td>\n",
       "      <td>GT3</td>\n",
       "      <td>T</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>at_home</td>\n",
       "      <td>...</td>\n",
       "      <td>5</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>3</td>\n",
       "      <td>4</td>\n",
       "      <td>5</td>\n",
       "      <td>5</td>\n",
       "      <td>6</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2</td>\n",
       "      <td>GP</td>\n",
       "      <td>F</td>\n",
       "      <td>15</td>\n",
       "      <td>U</td>\n",
       "      <td>LE3</td>\n",
       "      <td>T</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>at_home</td>\n",
       "      <td>...</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>10</td>\n",
       "      <td>7</td>\n",
       "      <td>8</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>3</td>\n",
       "      <td>GP</td>\n",
       "      <td>F</td>\n",
       "      <td>15</td>\n",
       "      <td>U</td>\n",
       "      <td>GT3</td>\n",
       "      <td>T</td>\n",
       "      <td>4</td>\n",
       "      <td>2</td>\n",
       "      <td>health</td>\n",
       "      <td>...</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>5</td>\n",
       "      <td>2</td>\n",
       "      <td>15</td>\n",
       "      <td>14</td>\n",
       "      <td>15</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>4</td>\n",
       "      <td>GP</td>\n",
       "      <td>F</td>\n",
       "      <td>16</td>\n",
       "      <td>U</td>\n",
       "      <td>GT3</td>\n",
       "      <td>T</td>\n",
       "      <td>3</td>\n",
       "      <td>3</td>\n",
       "      <td>other</td>\n",
       "      <td>...</td>\n",
       "      <td>4</td>\n",
       "      <td>3</td>\n",
       "      <td>2</td>\n",
       "      <td>1</td>\n",
       "      <td>2</td>\n",
       "      <td>5</td>\n",
       "      <td>4</td>\n",
       "      <td>6</td>\n",
       "      <td>10</td>\n",
       "      <td>10</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>5 rows × 34 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "   ID school sex  age address famsize Pstatus  Medu  Fedu     Mjob ... famrel  \\\n",
       "0   0     GP   F   18       U     GT3       A     4     4  at_home ...      4   \n",
       "1   1     GP   F   17       U     GT3       T     1     1  at_home ...      5   \n",
       "2   2     GP   F   15       U     LE3       T     1     1  at_home ...      4   \n",
       "3   3     GP   F   15       U     GT3       T     4     2   health ...      3   \n",
       "4   4     GP   F   16       U     GT3       T     3     3    other ...      4   \n",
       "\n",
       "  freetime goout  Dalc  Walc  health absences  G1  G2  G3  \n",
       "0        3     4     1     1       3        6   5   6   6  \n",
       "1        3     3     1     1       3        4   5   5   6  \n",
       "2        3     2     2     3       3       10   7   8  10  \n",
       "3        2     2     1     1       5        2  15  14  15  \n",
       "4        3     2     1     2       5        4   6  10  10  \n",
       "\n",
       "[5 rows x 34 columns]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.merge(left=si, right=sc, on='ID')\n",
    "df.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 3.把\"df\"所有的列展示出来(5分)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "Index(['ID', 'school', 'sex', 'age', 'address', 'famsize', 'Pstatus', 'Medu',\n",
       "       'Fedu', 'Mjob', 'Fjob', 'reason', 'guardian', 'traveltime', 'studytime',\n",
       "       'failures', 'schoolsup', 'famsup', 'paid', 'activities', 'nursery',\n",
       "       'higher', 'internet', 'romantic', 'famrel', 'freetime', 'goout', 'Dalc',\n",
       "       'Walc', 'health', 'absences', 'G1', 'G2', 'G3'],\n",
       "      dtype='object')"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df.columns"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 4.统计男生的平均分和女生的平均分(G1, G2, G3)，使用groupby和aggregate来操作(10分)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>G1</th>\n",
       "      <th>G2</th>\n",
       "      <th>G3</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>sex</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>F</th>\n",
       "      <td>10.620192</td>\n",
       "      <td>10.389423</td>\n",
       "      <td>9.966346</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>M</th>\n",
       "      <td>11.229947</td>\n",
       "      <td>11.074866</td>\n",
       "      <td>10.914439</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            G1         G2         G3\n",
       "sex                                 \n",
       "F    10.620192  10.389423   9.966346\n",
       "M    11.229947  11.074866  10.914439"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "<pandas.core.groupby.DataFrameGroupBy object at 0x10c442358>\n"
     ]
    }
   ],
   "source": [
    "df.groupby('sex')[['G1', 'G2', 'G3']].agg(np.mean)\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 5.统计不同年龄的学生(G1, G2, G3)的平均分，并作出柱状图展示（10分）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot object at 0x10c5b2f60>"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAENCAYAAAAfTp5aAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAE91JREFUeJzt3X2UXHV9x/HPBzZhTcKDJiMiYdnAUSRrTCALSqEqQQ3K\ncx8sUDEq7R5oCDa1BxDpgZaehsSeVnsI0IgIPgAqMRF8wEQC2LQSEkI0GwKWIwlsRLIJT1pcQ/Tb\nP2aSM6y7O9mZO3N3fnm/ztmTmXvvzv24kk9++5t7f+OIEACg+e2TdwAAQDYodABIBIUOAImg0AEg\nERQ6ACSCQgeARFDoAJAICh0AEkGhA0AiKHQASERLI082YcKEaG9vb+QpAaDpPfLII9siolDpuIYW\nent7u9asWdPIUwJA07O9eU+OY8oFABJBoQNAIih0AEhEQ+fQAaBeXn31VfX09Kivry/vKFVrbW3V\nxIkTNWrUqKq+v2Kh275F0umStkbE2/vt+3tJn5VUiIhtVSUAgAz09PRo//33V3t7u2znHWfYIkLb\nt29XT0+PJk2aVNVr7MmUy62STu2/0fZhkt4v6emqzgwAGerr69P48eObsswlybbGjx9f028YFQs9\nIn4k6fkBdv27pMsk8Rl2AEaEZi3zXWrNX9WborbPlLQlIn5S09kBICHPPfeczj//fB1xxBGaPn26\nTjjhBC1Zsk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pExHxM9sFSedFxH/kGrCM7bepuDrqQxHx67Ltp0bEvfkle61SzkMlrWrSnB+M\niMa+gZv3rywZ/urz8bwzkJOcIz2jpEtV/EyCpZI2STqrbN/avHI1cc45IylnU43Qh2L76YhoyztH\nJeTMVjPkHEkZba+XdEJE/Np2u6S7JH0lIj5v+9GIGClXDZGzCjWttthotn862C4V39gZEciZrWbI\n2QwZS/aN0rRARGwqTQ3eZftwjay5fnJWoakKXcW/GDNVvGa2nCXlPo9ahpzZaoaczZBRkn5pe1pE\nrJOk0sjydEm3SJqSb7TXIGcVmq3QvyNp3K4fXjnbDzQ+zqDIma1myNkMGSXpo5Je86Z8FN+k/6jt\n/8wn0oDIWYVk5tABYG83kq7dBgDUgEIHgERQ6ACQCAodABJBoWOvYXup7UdKS9x2lbZdaPtnth+w\n/QXb15e2F0pLoa4ufZ2Yb3qgMq5ywV7D9hsi4nnbr5O0WsXrxv9b0rGSfiVphYqrJl5i+3YV1wpa\nabtN0g8i4ujcwgN7oNmuQwdqcantc0qPD5N0gaQHI+J5SbL9TRUX15Kk90maXLag5wG294+IXzUy\nMDAcFDr2CqVbst+n4robr5Ru9nlC0mCj7n1Kx/6mMQmB2jGHjr3FgZJeKJX521T8eLAxkt5j+/W2\nWyT9adnxyyRdsuuJ7ZH0sWfAgCh07C3uldRSWkTrWkkPqbie+r9IWqXiR8c9Juml0vGXSup08TNr\nH5N0UeMjA8PDm6LYq9keV1pQqUXFzwS9JSKW5J0LqAYjdOztrrG9TsVPGXpKxQ8qAJoSI3QASAQj\ndABIBIUOAImg0AEgERQ6ACSCQgeARFDoAJCI/we9SsGHU3oVrgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<matplotlib.figure.Figure object at 0x10c499278>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df_data = df.groupby('age')[['G1', 'G2', 'G3']].agg(np.mean)\n",
    "df_data.plot(kind='bar')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 6.统计不同学校(school一列)的学生的平均分，并作柱状图展示，要求同一科目的两个学校成绩贴在一起展示(10分）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<matplotlib.axes._subplots.AxesSubplot object at 0x10c8ac518>"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAEACAYAAACj0I2EAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAALEgAACxIB0t1+/AAAEDdJREFUeJzt3W9wVQV6x/HfAyEkRsUA2TaQlUBHrUJg0ARatzgBVlS0\nwgvbQWXHrii1Ayxlln++AfvCcXV2Om1nHGYy2607uJPQ8Q+7i9aqyzq408GSiIuyaGehqNmwmKRd\nRCUVxqcvCDHEkOTec3Jv7sP3M8OYe+7JOU/mzHw9OTn3XnN3AQAK36h8DwAASAdBB4AgCDoABEHQ\nASAIgg4AQRB0AAiCoANAEAQdAIIg6AAQRFEudzZx4kSvrq7O5S4BoOC1tLR0uHvFYOvlNOjV1dVq\nbm7O5S4BoOCZ2ftDWY9LLgAQBEEHgCAIOgAEkdNr6AAwHE6fPq3W1lZ1dXXle5RESkpKVFVVpTFj\nxmT1/QQdQMFrbW3VZZddpurqaplZvsfJirurs7NTra2tmjp1albb4JILgILX1dWlCRMmFGzMJcnM\nNGHChES/ZRB0ACEUcszPSfozEHQACIKgA0AfTz31lFavXp3Ktqqrq9XR0ZHKtgYT+o+i1ZtfyOn+\njn7v9pzuDwB64wwdwEXj008/1e23365Zs2ZpxowZ2rFjh/bt26cbb7xRs2bN0pw5c3Ty5ElJUltb\nm2699VZdddVV2rhxY882GhsbVVNToxkzZmjTpk2DLs+l0GfoANDbSy+9pEmTJumFF87+9n7ixAnN\nnj1bO3bsUF1dnT7++GOVlpZKkt566y3t379fY8eO1TXXXKM1a9Zo9OjR2rRpk1paWlReXq5FixZp\n586dmjNnTr/Lly5dmtOfj6BjROJyGYZDTU2N1q9fr02bNumOO+7QFVdcocrKStXV1UmSLr/88p51\nFy5cqHHjxkmSrrvuOr3//vvq7OxUfX29KirOvvHhvffeqz179sjM+l2e66BzyQXARePqq69WS0uL\nampq9PDDD+v555+/4K2CY8eO7fl69OjROnPmjNy933UvtDzXOENP0yPjcry/E7ndH1Dg2traNH78\neC1fvlyXXnqpGhoa1NbWpn379qmurk4nT57sueTSn7lz52rt2rXq6OhQeXm5GhsbtWbNGs2ZM6ff\n5blG0AFcNN5++21t2LBBo0aN0pgxY7Rt2za5u9asWaNTp06ptLRUr7766gW/v7KyUo899pjmz58v\nd9fixYu1ZMkSSbrg8lyyXP6qUFtb67n8gIucX4ctuSen+4t8hs41dGTi0KFDuvbaa/M9Rir6+1nM\nrMXdawf7Xs7QAaQu1/9D/rf7puV0fyMVfxQFgCAIOgAEQdABIAiCDgBBEHQACGLQu1zM7IeS7pD0\nkbvP6F42XtIOSdWSjkr6S3f/3+EbExhmvCgslLTvshnKba3Hjx/XunXrtHfvXpWXl6u4uFgbN25U\neXm5lixZomnTpqmrq0vLli3T1q1bU53vnKGcoT8l6dY+yzZL+rm7XyXp592PAeCi5O5aunSpbrrp\nJh05ckQtLS1qampSa2urJGnevHnav3+/mpub9fTTT6ulpWVY5hg06O6+R9L/9Fm8RNKPur/+kaTc\nvgMNAIwgu3fvVnFxsR566KGeZVOmTPnKy//Lysp0ww036PDhw8MyR7bX0P/A3Y9JUvd/v3ahFc1s\npZk1m1lze3t7lrsDgJHr4MGDuv766wddr7OzU3v37tX06dOHZY5h/6Oouze4e6271557a0kAiGzV\nqlWaNWtWz9vyvv7665o9e7YWLVqkzZs3D1vQs33p/3Ezq3T3Y2ZWKemjNIcCgEIyffp0Pfvssz2P\nn3zySXV0dKi29uzbr8ybN0+7du0a9jmyPUP/qaT7ur++T9JP0hkHALLw+w+ktv1f/ktb7233s/0F\nCxaoq6tL27Zt61n22WefpT/HII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4x3h3P13kmRmH7j7e93L3j93GeZiRtCzs0/SO+7+H32fMLNHcj8OMnTa\nzP7wXBi6z9QXStol6Y/yOxoGY2aj3P0LSff3WjZaUnH+phoZeGFRFrr/AHPK3U/lexZkzsy+Kand\n3X/VZ/k4Savd/dH8TIbBmFmdpLfdvavP8imS5rn70/mZbGS46H9FydI8nX928IaZHen+d1ce58LQ\nlEn6s3MPzh0/Sfsl/VfepsJQTJK04tyDXsfuF+r/EuhFhaBnZ6POf2fJsZLqJNVL+pt8DISMDHT8\nHsrHQBgyjt0AuIaenWJ37/1pTb90905JnWZWlq+hMGQcv8LFsRsAZ+jZKe/9wN1X93pYkeNZkDmO\nX+Hi2A2AoGfnDTN7sO9CM/trSf+Zh3mQGY5f4eLYDYC7XLJgZl+TtFNn/wjzZvfiG3T2et5Sdz+e\nr9kwOI5f4eLYDYygJ2BmCyRN73540N1353MeZIbjV7g4dv0j6AAQBNfQASAIgg4AQRB0AAiCoANA\nEAQdAIL4f+eeMPTJO1iaAAAAAElFTkSuQmCC\n",
      "text/plain": [
       "<matplotlib.figure.Figure object at 0x10c89fa20>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "df_data = df.groupby('school')[['G1', 'G2', 'G3']].agg(np.mean)\n",
    "df_data.T.plot(kind='bar')"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 7.统计一下每个学校三个科目总分的前十名，然后把前十名的同学所有信息输出(10分)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 2.沃尔玛销售数据整理（共40分）"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 1. 数据导入并展示, 文件位置位于0.Teacher/data/walmart下 （10分）\n",
    "\n",
    "   - 请将文件 stores.csv 中的内容读入pandas DataFrame \"df_stores\"，并展示前五行以及打印df_stores的shape （2分）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Store</th>\n",
       "      <th>Type</th>\n",
       "      <th>Size</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>A</td>\n",
       "      <td>151315</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2</td>\n",
       "      <td>A</td>\n",
       "      <td>202307</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>3</td>\n",
       "      <td>B</td>\n",
       "      <td>37392</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>4</td>\n",
       "      <td>A</td>\n",
       "      <td>205863</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>5</td>\n",
       "      <td>B</td>\n",
       "      <td>34875</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Store Type    Size\n",
       "0      1    A  151315\n",
       "1      2    A  202307\n",
       "2      3    B   37392\n",
       "3      4    A  205863\n",
       "4      5    B   34875"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "(45, 3)"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('./Data/walmart/stores.csv')\n",
    "df.head(5)\n",
    "df.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "   - 请将文件 features.csv 中的内容读入pandas DataFrame \"df_feats\"，将df_feats改成只留下以下几个columns: \"Store\", \"Date\", \"Temperature\", \"Fuel_Price\", \"CPI\", \"Unemployment\", 并展示前五行以及打印df_feats的shape  （4分）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Store</th>\n",
       "      <th>Date</th>\n",
       "      <th>Temperature</th>\n",
       "      <th>Fuel_Price</th>\n",
       "      <th>CPI</th>\n",
       "      <th>Unemployment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2010-02-05</td>\n",
       "      <td>42.31</td>\n",
       "      <td>2.572</td>\n",
       "      <td>211.096358</td>\n",
       "      <td>8.106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2010-02-12</td>\n",
       "      <td>38.51</td>\n",
       "      <td>2.548</td>\n",
       "      <td>211.242170</td>\n",
       "      <td>8.106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2010-02-19</td>\n",
       "      <td>39.93</td>\n",
       "      <td>2.514</td>\n",
       "      <td>211.289143</td>\n",
       "      <td>8.106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2010-02-26</td>\n",
       "      <td>46.63</td>\n",
       "      <td>2.561</td>\n",
       "      <td>211.319643</td>\n",
       "      <td>8.106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2010-03-05</td>\n",
       "      <td>46.50</td>\n",
       "      <td>2.625</td>\n",
       "      <td>211.350143</td>\n",
       "      <td>8.106</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Store        Date  Temperature  Fuel_Price         CPI  Unemployment\n",
       "0      1  2010-02-05        42.31       2.572  211.096358         8.106\n",
       "1      1  2010-02-12        38.51       2.548  211.242170         8.106\n",
       "2      1  2010-02-19        39.93       2.514  211.289143         8.106\n",
       "3      1  2010-02-26        46.63       2.561  211.319643         8.106\n",
       "4      1  2010-03-05        46.50       2.625  211.350143         8.106"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "(8190, 6)"
      ]
     },
     "execution_count": 35,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('./Data/walmart/features.csv')\n",
    "# print(df)\n",
    "df.drop(['MarkDown1', 'MarkDown2', 'MarkDown3', 'MarkDown4', 'MarkDown5', 'IsHoliday'], axis=1, inplace=True)\n",
    "df.head(5)\n",
    "df.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "   - 请将文件 sales.csv 中的内容读入pandas DataFrame \"df_sales\"，并展示前五行以及打印df_sales的shape（4分）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Store</th>\n",
       "      <th>Dept</th>\n",
       "      <th>Date</th>\n",
       "      <th>Weekly_Sales</th>\n",
       "      <th>IsHoliday</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2010-02-05</td>\n",
       "      <td>24924.50</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2010-02-12</td>\n",
       "      <td>46039.49</td>\n",
       "      <td>True</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2010-02-19</td>\n",
       "      <td>41595.55</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2010-02-26</td>\n",
       "      <td>19403.54</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>2010-03-05</td>\n",
       "      <td>21827.90</td>\n",
       "      <td>False</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Store  Dept        Date  Weekly_Sales  IsHoliday\n",
       "0      1     1  2010-02-05      24924.50      False\n",
       "1      1     1  2010-02-12      46039.49       True\n",
       "2      1     1  2010-02-19      41595.55      False\n",
       "3      1     1  2010-02-26      19403.54      False\n",
       "4      1     1  2010-03-05      21827.90      False"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "text/plain": [
       "(421570, 5)"
      ]
     },
     "execution_count": 37,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df = pd.read_csv('./Data/walmart/sales.csv')\n",
    "df.head(5)\n",
    "df.shape"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 8. 我们发现 df_sales 中每个Store有很多个Dept(department)， 我们只关心整家店的销售情况，所以请把这张表格按照Store和Date来计算整店销售总额，IsHoliday这一列不必保留。结果保存在df_sales_by_store中。（10分）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th>Weekly_Sales</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>Store</th>\n",
       "      <th>Date</th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th rowspan=\"5\" valign=\"top\">1</th>\n",
       "      <th>2010-02-05</th>\n",
       "      <td>1643690.90</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-02-12</th>\n",
       "      <td>1641957.44</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-02-19</th>\n",
       "      <td>1611968.17</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-02-26</th>\n",
       "      <td>1409727.59</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2010-03-05</th>\n",
       "      <td>1554806.68</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  Weekly_Sales\n",
       "Store Date                    \n",
       "1     2010-02-05    1643690.90\n",
       "      2010-02-12    1641957.44\n",
       "      2010-02-19    1611968.17\n",
       "      2010-02-26    1409727.59\n",
       "      2010-03-05    1554806.68"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_sales_by_store = df_sales.groupby(['Store', 'Date']).agg(np.sum).drop(['IsHoliday', 'Dept'], axis=1)\n",
    "df_sales_by_store.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 9. 使用 Store 和 Date 这两列合并 df_sales_by_store 和 df_feats 两张表格，结果保存在 df_sale_feats 。（10分）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Store</th>\n",
       "      <th>Date</th>\n",
       "      <th>Weekly_Sales</th>\n",
       "      <th>Temperature</th>\n",
       "      <th>Fuel_Price</th>\n",
       "      <th>CPI</th>\n",
       "      <th>Unemployment</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>2010-02-05</td>\n",
       "      <td>1643690.90</td>\n",
       "      <td>42.31</td>\n",
       "      <td>2.572</td>\n",
       "      <td>211.096358</td>\n",
       "      <td>8.106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>2010-02-12</td>\n",
       "      <td>1641957.44</td>\n",
       "      <td>38.51</td>\n",
       "      <td>2.548</td>\n",
       "      <td>211.242170</td>\n",
       "      <td>8.106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>2010-02-19</td>\n",
       "      <td>1611968.17</td>\n",
       "      <td>39.93</td>\n",
       "      <td>2.514</td>\n",
       "      <td>211.289143</td>\n",
       "      <td>8.106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>2010-02-26</td>\n",
       "      <td>1409727.59</td>\n",
       "      <td>46.63</td>\n",
       "      <td>2.561</td>\n",
       "      <td>211.319643</td>\n",
       "      <td>8.106</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>2010-03-05</td>\n",
       "      <td>1554806.68</td>\n",
       "      <td>46.50</td>\n",
       "      <td>2.625</td>\n",
       "      <td>211.350143</td>\n",
       "      <td>8.106</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Store        Date  Weekly_Sales  Temperature  Fuel_Price         CPI  \\\n",
       "0      1  2010-02-05    1643690.90        42.31       2.572  211.096358   \n",
       "1      1  2010-02-12    1641957.44        38.51       2.548  211.242170   \n",
       "2      1  2010-02-19    1611968.17        39.93       2.514  211.289143   \n",
       "3      1  2010-02-26    1409727.59        46.63       2.561  211.319643   \n",
       "4      1  2010-03-05    1554806.68        46.50       2.625  211.350143   \n",
       "\n",
       "   Unemployment  \n",
       "0         8.106  \n",
       "1         8.106  \n",
       "2         8.106  \n",
       "3         8.106  \n",
       "4         8.106  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "df_sale_feats = pd.merge(left=df_sales_by_store, right=df_feats, on=['Store', 'Date'])\n",
    "df_sale_feats.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "#### 10. 使用 Store 这一列合并 df_sale_feats 和 df_stores 两张表格，结果仍然保留在df_sale_feats 中。（10分）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "***\n",
    "<center><h1>####答卷结束####</h1></center>"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 本周课程意见反馈(非必答)\n",
    "请同学围绕以下两点进行回答：\n",
    "- 自身总结：您自己在本周课程的学习，收获，技能掌握等方面进行总结，包括自身在哪些方面存在哪些不足，欠缺，困惑。作为将来回顾学习路径时的依据。\n",
    "- 课程反馈：也可以就知识点，进度，难易度，教学方式，考试方式等等进行意见反馈，督促我们进行更有效的改进，为大家提供更优质的服务。"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "自身总结：基础不够，很多知识点不知如何入手<br>\n",
    "课程反馈："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
